<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>node learn</title>
	<script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
	<link rel="stylesheet" href="it.css">
</head>
<body>
	
	<div class="name"><input placeholder="姓名" type="text"></div>
	
	<div class="phone"><input placeholder="联系号码" type="tel"></div>
	
	<div class="intro"><textarea placeholder="爱好，性格，兴趣等（256字以内）" type="text"></textarea></div>
	
	<div id="sent"><p>点击发送</p></div>
</body>
<script type="text/javascript">
$(document).ready(function(){
	$("#sent").click(function(){
		var name = $(".name input").val(); 
		var phone = $(".phone input").val(); 
		var intro = $("textarea").val();

		if (phone.length != 11 || !(/^1[3|4|5|7|8]\d{9}$/.test(phone))){
			alert("请输入有效的手机号码！");
			return; 
		} 
		else if (intro.length > 255) {
			alert("个人介绍似乎有点长了...");
			return; 
		}
        else if (name.length > 10) {
			alert("名字填写错误");
			return; 
		}
		$.ajax({
			type: 'post',
			async: true,
			url: "http://eczn.website:8086", 
			data: {
				name: name,
				phone: phone,
				intro: intro
			},
			dataType: 'json',
			success: function(data){
				console.log(data);
				console.log("success");
				alert("报名成功！"); 
			},
			error: function(data){
				console.warn("faild");
				console.log("报名失败！ ");
				console.log(data); 
			}
		});

	});
});

</script>
</html>
